package mainSocket;

import java.awt.AWTException;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;


import storage.UserAccessManager;

import entity.User;

public class Server extends Thread
{
	private static boolean running = true;
	private ServerSocket serverSocket;
	public void run()
	{
		do
		{
			System.out.println("Waiting for a Client");
		
			Socket newClientSocket = null;
			try 
			{
				newClientSocket = serverSocket.accept();
			} 
			catch (IOException e) 
			{
				e.printStackTrace();
			} 
			Thread kickoff = new Thread(new Listener(newClientSocket));
			kickoff.start();
		}
		while (true);
	}
	public Server() throws IOException
	{
		serverSocket = new ServerSocket(0);
		
	}
	public static boolean isRunning()
	{
		return running;
	}	
	
	public int getPort()
	{
		return serverSocket.getLocalPort();
	}
}
